<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>游戏渠道数据统计</title>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
</head>
#parse("/views/default/defaultValue.vm")
<body>
<script type="text/javascript" src="http://pic2.58.com/n/tuan/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../javascript/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="../javascript/report/FusionCharts.js"></script>
<script type="text/javascript" src="../javascript/report/Date.js"></script>
<script >
		var functions = $("#functions").val();
		
		
		function check(){
			var startDate = $("#startDate").val();
			if(startDate == ""){
				alert("请选择起始时间!");
				return false;
			}
			var endDate = $("#endDate").val();
			if(endDate == ""){
				alert("请选择截止时间!");
				return false;
			}
			
			if(startDate>endDate){
				alert("截止时间不能大于起始时间!");
				return false;
			}

		}
		
		
		var type = $("#type").val();
		$(function(){
		$("#download").click(function(){
			$("#down").val(1);
			document.sourcestat.submit();
		});
		});
		
		function order(name){
			$("#down").val(0);
			$("#orderBy").val(name);
			document.sourcestat.submit();
		}
		
	
		$(function(){
            $("#companyId").change(function(){
                var companyId = $("#companyId").val();
                if(companyId != "" && companyId !="全部"  ){
                
 					jQuery.ajax({
                    type:"POST",
                    dataType:"json",
                    async:true,
                    url:"/game/getgames",
                    data:{"companyId":companyId},
                    success:function(data){
                        if(data!=""){
                            var cityitems = "";
    						cityitems = "<option value='0'>全部</option>";
                            $.each(data.items, function(i, obj) {
                                cityitems = cityitems + "<option value='"+obj.game_id+"'>"+obj.game_name+"</option>";
                            });
                            $("#gameId").empty().append(cityitems);
						}
                    }
                });
                }else{
					 var cityitems = "<option value=''>全部</option>";
					 $("#gameId").empty().append(cityitems);
				}
           	 });
   		 });	

	
		

		
		 $(function(){
            $("#gameId").change(function(){
			 	var companyId = $("#companyId").val();
                var gameId = $("#gameId").val();
				//alert(companyId + "   " +gameId);
				
                if(gameId != "" && gameId !="全部" && companyId != "" && companyId !="全部"   ){
                   
					//alert(companyId + "   " +gameId);

					jQuery.ajax({
                    type:"POST",
                    dataType:"json",
					async:true,
                    url:"/game/getservers",
                    data:{"companyId":companyId,"gameId":gameId},
                    success:function(data){
					//alert(data);
                        if(data!=""){
                            var cityitems = "";
							
    						cityitems = "<option value='0'>全部</option>";
                            $.each(data.items, function(i, obj) {
                                cityitems = cityitems + "<option value='"+obj.server_id+"'>"+obj.server_name+"</option>";
                            });
                            $("#serverId").empty().append(cityitems);
                        }
                    }
                });
				
                }else{
					 var cityitems = "<option value=''>全部</option>";
					 $("#serverId").empty().append(cityitems);
				}
           	 });
   		 });


	
	
	
		 var pics ="";
		 function addpics(value){
			var fs = pics.split(",");
			var newfs ="";
			var flag = false;
			for(var i=0;i<fs.length;i++){
				var f = fs[i];
				if(f!=""){
    				if(f == value){
    				  flag = true;
    				  continue;
    				}
    				newfs = newfs + f+",";
				}
			}
			if(!flag){
				newfs = newfs + value+",";
			}
			pics = newfs;
			$("#pics").val(pics);
//			alert(pics);
		}
		
		
		  $(function(){$("#picsclear").click(function(){
		 		var code_Values = document.getElementsByName('pics');
		 		if(code_Values.length > 0){ 
					for(var i=0;i<code_Values.length;i++){
						code_Values[i].checked = false; 
					}
					pics = "";
					$("#pics").val(pics);
				}
				
				var code_Values2 = document.getElementsByName('pics_pie');
		 		if(code_Values2.length > 0){ 
					for(var i=0;i<code_Values2.length;i++){
						code_Values2[i].checked = false; 
					}
					pics_pie = "";
					$("#pics_pie").val(pics_pie);
				}
		 	})
		 })
		
</script>
<div class="lr_both" style="OVERFLOW-X:yes;OVERFLOW-Y:auto" >
<div class="right_conts">
  <div class="mg_tt">
    <div class="right_search">
      <div class="rs_title_bg">
        <h2 class="rs_title">游戏渠道数据统计</h2>
      </div>
	  </br>
	  <form id="sourcestat" name="sourcestat" action="/game/sourcestat" method="post" onsubmit="return check();">
	  <input type="hidden" id="down" name="down" value="0"/>
	  <input type="hidden"  id="orderBy" name="orderBy" value="$!{orderBy}"/>
	  <input type="hidden"  id="pics" name="pics" value="$!{pics}"/>
	  <input type="hidden"  id="IndexList" name="IndexList" value="$!{IndexList}"/>
	  
      <div class="rs_div" style="height:50px;" > 
		<div pd_text="" style="height:25px;">
			起始时间:&nbsp;<input  type="text" id="startDate" name="startDate" class="Wdate" value="$!{startDate}" onclick="WdatePicker({skin:'ext',dateFmt:'yyyy-MM-dd'})"/>
    		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			结束时间:&nbsp;<input  type="text" id="endDate" name="endDate" class="Wdate" value="$!{endDate}"   onclick="WdatePicker({skin:'ext',dateFmt:'yyyy-MM-dd'})"/>
			&nbsp;&nbsp;
			
		</div>
        <div  pd_text="" style="height:25px;">
			查询维度:&nbsp;
    			<select size="1"  name="type" id="type">
					<option value="0" #if($type=="0") selected #end>渠道</option>
					<option value="1" #if($type=="1") selected #end>游戏</option>
					<option value="2" #if($type=="2") selected #end>区服</option>
                </select>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	
			厂商:&nbsp;
			<select size="1"  name="companyId" id="companyId">
					<option value="0">全部</option>
					#if($gameCompanyList)
    					#foreach($gameCompany in $gameCompanyList)
    						<option value="${gameCompany.company_id}" #if (${gameCompany.company_id}== $companyId) selected #end >${gameCompany.company_name}</option>
						#end
					#end
			</select>	
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			游戏:&nbsp;
			<select size="1"  name="gameId" id="gameId">
					<option value="0">全部</option>
					#if($gameList)
    					#foreach($game in $gameList)
    						<option value="${game.game_id}" #if (${game.game_id}== $gameId) selected #end >${game.game_name}</option>
						#end
					#end
                 </select>	
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			服务器:&nbsp;
			<select size="1"  name="serverId" id="serverId">
					<option value="0">全部</option>
					#if($serviceList)
    					#foreach($server in $serviceList)
    						<option value="${server.server_id}" #if (${server.server_id}== $serverId) selected #end >${server.server_name}</option>
						#end
					#end
                 </select>	
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="submit" value="查询"/>
		</div>
     </div>
	 </form>
	 
	#if($rsList)
    <div class="table_div" style="OVERFLOW-X:yes;OVERFLOW-Y:auto">
      <table class="sj_tl sj_tl_2" width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr style="background:#ffd9b5;">
			#if($type == 0)		
				<td align="center" >渠道</td>
				#elseif($type == 1)
					<td align="center" >游戏</td>
					#elseif($type == 2)
						<td align="center" >区服</td>
						#end
					
		   #foreach($dic in $dicList)
			<td align="center" ><a onclick=order("$dic.split(',')[0]")>$dic.split(',')[1]</a></td>
		   #end
        </tr>
		
		<tr>
			<td align="center" >汇总</td>
				#foreach($dic in $dicList)
					#if($dic.split(',')[0] == "ARPU" || $dic.split(',')[0]== "payAmount" )
						<td align="center" >$tools.xsd($tools.getValues($dic.split(',')[0],$countAllRecord,$class))<input type="checkbox" style="float:right;" name="pics" id="pics"  onclick="addpics('汇总'+':'+'$dic.split(',')[0]')"/></td>
					#elseif($dic.split(',')[0] == "channel_name" || $dic.split(',')[0] == "game_name" ||$dic.split(',')[0] == "server_name" )						
						<td align="center" >$tools.getValues($dic.split(',')[0],$countAllRecord,$class)</td>
					#else
						<td align="center" >$tools.qfw($tools.getValues($dic.split(',')[0],$countAllRecord,$class))<input type="checkbox" style="float:right;" name="pics" id="pics"  onclick="addpics('汇总'+':'+'$dic.split(',')[0]')"/></td>
					#end
    		   #end			
        </tr>
		
		
		
			   
			   
			   
        #foreach($rs in $rsList)
		<tr onMouseOver="this.className='tdbg10'" onMouseOut="this.className='tdbg11'" class="tdbg11">
			#if($type == 0)		
				<td align="center" >$!{rs.channel_name}</td>
				#elseif($type == 1)
					<td align="center" >$!{rs.game_name}</td>
					#elseif($type == 2)
						<td align="center" >$!{rs.server_name}</td>
						#end
				
			   #foreach($dic in $dicList)
					#if($dic.split(',')[0] == "ARPU" || $dic.split(',')[0]== "payAmount" )
						#if($type == 0)		
							<td align="center" >$tools.xsd($tools.getValues($dic.split(',')[0],$rs,$class))<input type="checkbox" style="float:right;" name="pics" id="pics"  onclick="addpics('$!{rs.channel_name}'+':'+'$dic.split(',')[0]')"/></td>
						#elseif($type == 1)
							<td align="center" >$tools.xsd($tools.getValues($dic.split(',')[0],$rs,$class))<input type="checkbox" style="float:right;" name="pics" id="pics"  onclick="addpics('$!{rs.game_name}'+':'+'$dic.split(',')[0]')"/></td>
						#elseif($type == 2)
							<td align="center" >$tools.xsd($tools.getValues($dic.split(',')[0],$rs,$class))<input type="checkbox" style="float:right;" name="pics" id="pics"  onclick="addpics('$!{rs.server_name}'+':'+'$dic.split(',')[0]')"/></td>
						#end
						
					#elseif($dic.split(',')[0] == "channel_name" || $dic.split(',')[0] == "game_name" ||$dic.split(',')[0] == "server_name" )
						<td align="center" >$tools.getValues($dic.split(',')[0],$rs,$class)</td>
					#else
						#if($type == 0)		
							<td align="center" >$tools.qfw($tools.getValues($dic.split(',')[0],$rs,$class))<input type="checkbox" style="float:right;"  name="pics" id="pics"  onclick="addpics('$!{rs.channel_name}'+':'+'$dic.split(',')[0]')"/></td>
						#elseif($type == 1)
							<td align="center" >$tools.qfw($tools.getValues($dic.split(',')[0],$rs,$class))<input type="checkbox" style="float:right;" name="pics" id="pics"  onclick="addpics('$!{rs.game_name}'+':'+'$dic.split(',')[0]')"/></td>
						#elseif($type == 2)
							<td align="center" >$tools.qfw($tools.getValues($dic.split(',')[0],$rs,$class))<input type="checkbox" style="float:right;" name="pics" id="pics"  onclick="addpics('$!{rs.server_name}'+':'+'$dic.split(',')[0]')"/></td>
						#end
					#end
    		   #end			   
        </tr>
		#end
      </table>
	  </br>
	   <div align="right">
		#if($rsList.size() >0 )
		<input align="left" type="button" id="download" name="download" value="下载Excel报表"/>
		#end
		#parse("/views/default/page.vm")
        #pagebar($pList "/game/sourcestat?#page#&$paramurl")
	   </div>
    </div>
	
	##绘图
	<div class="rs_div" style="height:30px;"> 
		<div pd_text="" style="height:25px;">
            <span style="color:red">1、图表查看(指标请在上面勾选)：</span>
			&nbsp;&nbsp;&nbsp;<input type="button"   name="moresearch" id="moresearch"  value="绘图"/> 
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button"   name="picsclear" id="picsclear"  value="重置绘图所有勾选项"/>
        </div>
		
    </div>

	#end
  </div>
  	 </br>
	 <div id="chartdiv" align="center"  style="float:center;padding-left:20px;"></div>
	 
	<script type="text/javascript">
		 $(function(){$("#moresearch").click(function(){
		 		var pics = $("#pics").val();
		 		if("" == pics){
					alert("请选择绘图指标！");
					return false;
				}
				
				if(pics.lastIndexOf(",")+1 == pics.length){
					pics = pics.substring(0,pics.lastIndexOf(","));
				}
		 		
				var fs = pics.split(",");
				if(fs.length > 10){
					alert("最多只能选择10个指标进行绘图！");
					return false;
				}
				
            	jQuery.ajax({
        			url:"/game/sourcemoresearch",
            		type:"post",
					dataType:"json",
            		async:true,
            		data:{"pics":pics,"startDate":$("#startDate").val(),"endDate":$("#endDate").val(),"type":$("#type").val(),"companyId":$("#companyId").val(),"gameId":$("#gameId").val(),"serverId":$("#serverId").val()},
            		success:function(data){
						var result = data.result;
						if(result == "NODATA"){
							alert("无数据！");
						}else{
						  var chart ;
						  if(result.indexOf("LINEDY") > -1){
							chart = new FusionCharts("../image/swf/fusionChartsCracker.swf?chartUrl=../image/swf/MSColumn3DLineDY.swf", "ChartId", "970", "350", "0", "0");
						  }else if(result.indexOf("LINE2D") > -1){
							chart = new FusionCharts("../image/swf/fusionChartsCracker.swf?chartUrl=../image/swf/MSLine.swf", "ChartId", "970", "350", "0", "0");
						  }
						  var xml = result.substring(result.indexOf(":")+1);
						  chart.setDataXML(xml);	
					      chart.render("chartdiv");
						}
            		}
            	});
        	 })
         })
		
    </script>
</div>
</div>
</div>
</body>
</html>
